class CacheService {
  // 设置项
  static setItem<T>(key: string, value: T): void {
    localStorage.setItem(key, JSON.stringify(value))
  }

  // 获取项
  static getItem<T>(key: string): T | null {
    const item = localStorage.getItem(key)
    return item ? JSON.parse(item) : null
  }

  // 移除项
  static removeItem(key: string): void {
    localStorage.removeItem(key)
  }

  // 清空所有项
  static clear(): void {
    localStorage.clear()
  }
}

export default CacheService
